package com.zysoft.function;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * @author wmf
 * 用法：
 * Stroage stroage = new Stroage();
 * stroage.setName("武汉智远",Context);
 * stroage.getName(Context).toString()
 */
public class Stroage {

    public SharedPreferences share(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("project", Context.MODE_PRIVATE);
        return sharedPreferences;
    }
    //账号
    public  boolean setUser(String name, Context context){
        SharedPreferences.Editor e = share(context).edit();
        e.putString("user",name);
        Boolean bool = e.commit();
        return bool;
    }
    //密码
    public  boolean setPassword(String name, Context context){
        SharedPreferences.Editor e = share(context).edit();
        e.putString("password",name);
        Boolean bool = e.commit();
        return bool;
    }
    //公司编码
    public  boolean setProcode(String name, Context context){
        SharedPreferences.Editor e = share(context).edit();
        e.putString("corpCode",name);
        Boolean bool = e.commit();
        return bool;
    }
    //缓存项目名称
    public  boolean setName(String name, Context context){
        SharedPreferences.Editor e = share(context).edit();
        e.putString("name",name);
        Boolean bool = e.commit();
        return bool;
    }
    //缓存项目code
    public  boolean setCode(String code, Context context){
        SharedPreferences.Editor e = share(context).edit();
        e.putString("code",code);
        Boolean bool = e.commit();
        return bool;
    }
    //缓存登录状态 离线登录1 在线登录0
    public  boolean setState(String state, Context context){
        SharedPreferences.Editor e = share(context).edit();
        e.putString("state",state);
        Boolean bool = e.commit();
        return bool;
    }
    public Object getUser(Context context){ return share(context).getString("user",null);}

    public Object getPassword(Context context){return share(context).getString("password",null);}

    public Object getProcode(Context context){return share(context).getString("corpCode",null);}

    public  Object getName(Context context){
        return share(context).getString("name",null);
    }

    public  Object getCode(Context context){
        return share(context).getString("code",null);
    }

    public  Object getState(Context context){
        return share(context).getString("state",null);
    }
}
